package javabase.net.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class SocketServiceApp {
	
	private ServerSocket serverSocket = null;
	
	public ServerSocket getServerSocket() {
		return serverSocket;
	}

	public void setServerSocket(ServerSocket serverSocket) {
		this.serverSocket = serverSocket;
	}

	public SocketServiceApp(int port) {
		try {
			this.serverSocket = new ServerSocket(port);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) throws Exception {
		System.out.println("服务器启动中。。。在9999端口监听");
		SocketServiceApp service = new SocketServiceApp(9999);
		ServerSocket serverSocket = service.getServerSocket();
		Socket socket = serverSocket.accept();
		InputStream is = socket.getInputStream();
		InputStreamReader isr = new InputStreamReader(is);
		BufferedReader br = new BufferedReader(isr);
		System.out.println("服务器收到的消息：" + br.readLine());
		
		System.out.println("---华丽的分割线---");
	}

}
